package net.TCPMORE;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1", 6666);
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(outputStream);
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入");
            String s = scanner.nextLine();
            if ("exit".equals(s)){
                System.out.println("退出了");
                break;
            }
            dos.writeUTF(s);
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                try (InputStream inputStream = socket.getInputStream();
                     DataInputStream dis = new DataInputStream(inputStream)
                ) {
                    String s = dis.readUTF();
                    System.out.println(s);
                } catch (IOException e) {
                    System.out.println("有人下线了");
                }

            }
        }).start();
        dos.close();
        socket.close();
    }
}
